<template>
	<view class="inform">
		<view class="inform-template">
			<view class="inform-template-left">选择模板</view>
			<view class="inform-template-right" @click="optionalModule">
				<view>销售订单转发货指令</view>
				<image src="@/static/image/more_right_icon.png"></image>
			</view>
		</view>
		<view class="inform-template">
			<view class="inform-template-left">推送方式</view>
			<view class="inform-template-right">
				<view>{{informData.pushMode}}</view>
			</view>
		</view>
		<view class="inform-object">
			<view style="font-weight: 700;">通知对象</view>
			<view class="inform-object-list"  @click="notifyObject">
					<view v-for="item,index in informData.noticeObjTemps" :key='item.objId'>{{item.objName}}</view>
				
			</view>
		</view>
		<view class="inform-object">
			<view>通知内容</view>
			<view class="inform-object-list" style="height: 450rpx;">
				{{informData.templateName?informData.templateName:''}}
			</view>
		</view>
		<view class="inform-Btn">
			<view class="inform-Btn-cancel" @click="cancel">取消</view>
			<view class="inform-Btn-confirm" @click="confirmSend">确认并发送</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/utils/api.js';
	export default {
		data() {
			return {
				informObject:"",
				informContent:"",
				informList:{},
				informData:{},
				templateList:[],
				sourceId:'',
				orderNo:'',
				userId:'',
				userName:'',
				noticeObjTempId:''
			}
		},
		onLoad(option){
			this.sourceId = option.id
			this.orderNo = option.orderNo
			this.notifyInfo()
			
			let data = getApp().globalData.userInfo
			data.employee.forEach(item=>{
				if(item.isDefault == '0'){
					this.userId = item.employeeId
					this.userName= item.employeeName
				}
			})
		},
		onShow(){
			let pages = getCurrentPages();  
			let nowPage = pages[pages.length - 1];
			let { departmentList } = nowPage.data
			if(departmentList){
				this.noticeObjTempId = departmentList.id
				this.informData.noticeObjTemps = departmentList.noticeObjDTOS
			}
		},
		onUnload(){
			uni.navigateBack({delta:1})
		},
		methods: {
			notifyInfo(){
				let data = { triggerButton:"1254355793118101504" }
				api.sendNoticePage(data).then(res=>{
					if(res.code == 0){
						let { result } = res.data
						this.informData = result
					}
				})
				api.sendTempList(data).then(res=>{
					if(res.code == 0){
						let { result } = res.data
						this.templateList = result
					}
				})
			},
			optionalModule(){
				let that = this
				let template = []
				that.templateList.forEach(item=>{
					arr.push(item.templateName)
				})
				uni.showActionSheet({
					itemList: template,
					success: function(res) {
						that.notifyInfo()
						that.noticeObjTempId = ''
						that.templateList = []
					}
				});
			},
			notifyObject(){
				uni.navigateTo({
					url: '/subcontractList/order/salesAdmin/salesOrder/newsNotification/selectObject'
				});	
			},
			cancel(){
				uni.navigateBack({delta: 2})
			},
			confirmSend(){
				let data = this.informData
				let form = {
					appDirection:"salOrder-detail",
					documentNo:this.orderNo,
					noticeContent:data.noticeContent,
					noticeObjTempId: this.noticeObjTempId ? this.noticeObjTempId :data.noticeObjTempId,
					noticeSource:"销售订单",
					pushMode:data.pushMode,
					routerPath:"orderFinish",
					sourceId:this.sourceId,
					userId:this.userId,
					userName:this.userName
				}
				
				api.sendNotice(form).then(res=>{
					if(res.code == 0){
						uni.navigateBack({delta: 2})
						uni.showToast({
							title:'发送成功',
							icon:'none',
							duration: 2000
						});	
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.inform{
	height: 100vh;
	background-color: #eeeeee;
	&-template{
		padding: 20rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 20rpx;
		&-left{
			color: #0f0f0f;
			font-weight: 700;
		}
		&-right{
			display: flex;
			align-items: center;
			image{
				width: 30rpx;
				height: 30rpx;
			}
		}
	}
	&-object{
		padding: 0 20rpx;
		&-list{
			width: 100%;
			height: 300rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin-top: 10rpx;
			padding: 20rpx;
			box-sizing: border-box;   
		}
	}
	&-Btn{
		position: fixed;
		left: 0;
		bottom: 20rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-around;
		
		&-cancel,&-confirm{
			width: 45%;
			padding: 15rpx 0;
			color: #fff;
			border-radius: 10rpx;
			background-color: #888888;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		&-confirm{
			background-color: #66cc33;
		}
	}
	
}
</style>
